package mianshi;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * description:
 * author:zt
 * date:2021-08-06
 */
public class _08_04 {
    List<List<Integer>> res = new ArrayList<>();
    List<Integer> path = new ArrayList<>();
    boolean[] used;
    public List<List<Integer>> subsets(int[] nums) {
        if (nums.length==0 || nums==null) return new ArrayList<>();
        used = new boolean[nums.length];
        Arrays.sort(nums);
        dfs(nums,0,nums.length);
        res.add(new ArrayList<>());
        return res;
    }
    public void dfs(int[] nums,int begin,int len){
        for (int i = begin; i < len; i++) {
            if (!used[i]){
                if (i>0 && nums[i]==nums[i-1] && !used[i-1]) continue;
                used[i] = true;
                path.add(nums[i]);
                res.add(new ArrayList<>(path));
                dfs(nums,i+1,len);
                used[i] = false;
                path.remove(path.size()-1);
            }
        }
    }
}
